package com.ujiuye.service.impl;

import com.ujiuye.dao.CourseUserDao;
import com.ujiuye.dao.impl.CourseUserDaoImpl;
import com.ujiuye.entity.Course;
import com.ujiuye.entity.CourseUser;
import com.ujiuye.service.CourseUserService;
import com.ujiuye.util.PageBean;

import java.util.List;

public class CourseUserServiceImpl implements CourseUserService {
    CourseUserDao cud= new CourseUserDaoImpl();
    @Override
    public PageBean<CourseUser> findByPage(String currentPage1, String pageSize1) {

        if(currentPage1 == null || "".equals(currentPage1)){
            currentPage1 = "1";
        }

        if(pageSize1 == null || "".equals(pageSize1)){
            pageSize1 = "3";
        }

        //1:声明变量
        int currentPage = Integer.parseInt(currentPage1);
        int pageSize = Integer.parseInt(pageSize1);
        int totalCount = cud.totalCount();
        int totalPage  = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        int startIndex = pageSize * (currentPage-1);//起始的行下标
        List<CourseUser> list = cud.findAllCs(startIndex,pageSize);
        PageBean pb = new PageBean(currentPage,pageSize,totalCount,totalPage,list);

        return pb;
    }

    @Override
    public int delAll(String ids) {
        return cud.delAll(ids);
    }

    @Override
    public List<Course> findAllCourse() {
        return cud.findAllCourse();
    }

    @Override
    public int updateCourseById(int id, int cid) {
        return cud.updateCourseById(id,cid);
    }

    @Override
    public int insertCourseUser(int uid, int cid) {
        return cud.insertCourseUser(uid,cid);
    }

    @Override
    public CourseUser findCourseUser(int uid, int cid) {
        return cud.findCourseUser(uid,cid);
    }


}
